//@author A0105536L
package Logic;

import Object.DSException;
import Object.DSQuery;
import Storage.DSStorage;
import Task.DSTask;
import Task.DSTaskList;

/****************************************************************************
 * Class DSCommandExecuter. This class executes command after DSCommandParser
 * determines the command type.
 * 
 * 
 * 
 */
public class DSCommandExecuter {

	static DSStorage _storage;

	/**
	 * Constructor of this class
	 * 
	 * @throws DSException
	 */
	public DSCommandExecuter() throws DSException {
		_storage = new DSStorage();
	}

	/**
	 * This method is to execute add command
	 * 
	 * @param newTask
	 *            DSTask that to be added
	 * @return True if add command succeeds
	 * @throws DSException
	 */
	public boolean add(DSTask newTask) throws DSException {
		return _storage.add(newTask);
	}

	/**
	 * This method is to execute delete command
	 * 
	 * @param TaskID
	 *            TaskID that the task to be deleted
	 * @return True if delete command succeeds
	 * @throws DSException
	 */
	public boolean delete(String TaskID) throws DSException {
		return _storage.remove(TaskID);
	}

	/**
	 * This method is to exit program
	 */
	public void exit() {
		System.exit(0);
	}

	/**
	 * This method is to execute update command
	 * 
	 * @param updateTask
	 *            DSTask that to be updated
	 * @return True if update command succeeds
	 * @throws DSException
	 */
	public boolean update(DSTask updateTask) throws DSException {
		return _storage.update(updateTask);
	}

	/**
	 * This method is to execute search command
	 * 
	 * @param query
	 *            DSQuery that contains all information that for searching
	 * @return True if search command succeeds
	 * @throws DSException
	 */
	public DSTaskList search(DSQuery query) throws DSException {
		return _storage.search(query);
	}

	/**
	 * This method is to execute all command
	 * 
	 * @return True if all command succeeds
	 * @throws DSException
	 */
	public DSTaskList displayall() throws DSException {
		return _storage.getTaskList();
	}

	/**
	 * This method is to execute undo command
	 * 
	 * @return True if undo command succeeds
	 * @throws DSException
	 */
	public DSTaskList undo() throws DSException {
		return _storage.undo();
	}
	
	/**
	 * This method is to get background number
	 * @return
	 * 				get background number
	 * @throws DSException
	 */
	public int getBackgroundNum() throws DSException{
		return _storage.getBackgroundNum();
	}
	/**
	 * This method is to get animation status
	 * @return
	 * 				get animation status
	 * @throws DSException
	 */
	public boolean isAnimated() throws DSException{
		return _storage.isAnimated();
	}
	public void setAnimation(boolean status) throws DSException{
		_storage.updateAnimation(status);
	}
	
	public void setBackgroundNum(int bgn) throws DSException{
		_storage.updateBackgroundNum(bgn);
	}
	
	public DSTaskList getTaskList() throws DSException {
		return _storage.getTaskList();
	}

}